﻿function ClientAddSite()
{
    Url = Portal.SystemWebParts.Site.Site.GetAddSiteUrl().value;
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    window.open(Url, '_blank');
    //value=Portal.SystemWebParts.Site.Site.GetHtml().value;
//    if(value.indexOf("ERROR")==-1)
//    {
//        document.getElementById("divSiteMain").innerHTML=value;
//    }
}

function ClientSaveAddSite()
{
    SiteCode=document.getElementById("txtSiteCode").value;
    SiteName=document.getElementById("txtSiteName").value;
    IndexOrder = document.getElementById("txtIndexOrder").value;
    retValue = Portal.SystemWebParts.Site.AddSite.ServerSideAddSite(SiteCode, SiteName, IndexOrder).value;
    if(retValue.indexOf("ERROR")!=-1)
    {
        alert(retValue);
        return;
    }
    alert(retValue  );
    window.close();
}


function ClientDeleteSite(SiteId)
{
    Msg=Portal.SystemWebParts.Site.Site.GetConfirmDeleteMsg().value;
    if(confirm(Msg)==false)return;
    RetValue = Portal.SystemWebParts.Site.Site.ServerSideDeleteSite(SiteId).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    value=Portal.SystemWebParts.Site.Site.GetHtml().value;
    if(value.indexOf("ERROR")==-1)
    {
        document.getElementById("divSiteMain").innerHTML=value;
    }
}


function ShowClientUpdateUrlForm(SiteCode)
{
    Url = Portal.SystemWebParts.Site.Site.GetShowUpdateForm(SiteCode).value;
    if(Url.indexOf("ERROR")!=-1)
    {
        alert(Url);
        return;
    }
    //window.showModalDialog(Url, null, 'dialogHeight: 600px; dialogWidth: 800px; dialogTop: 10px; dialogLeft: 150px; edge: Raised; center: Yes; help: No; scroll: Yes; status: Yes;');
    window.open(Url, '_blank');
    //JumPageSite();
}


function ShowSyncSiteForm(SiteCode) {
    Url = Portal.SystemWebParts.Site.Site.GetShowSyncSiteForm(SiteCode).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
}


function ClientSaveUpdateSite(SiteCode)
{
    SiteName=document.getElementById("txtSiteName").value;
    IndexOrder = document.getElementById("txtIndexOrder").value;
    RetValue = Portal.SystemWebParts.Site.UpdateSite.ServerSideUpdateSite(SiteCode, SiteName, IndexOrder).value;
    if(RetValue.indexOf("ERROR")!=-1)
    {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    window.close();
}

function ClientReadingSite() {
    document.getElementById("divProcessing").innerHTML = Portal.SystemWebParts.Site.Site.GetProcessingText().value;
    setTimeout("RealClientReadingSite()", 10);
}

function RealClientReadingSite() {
    document.getElementById("divSiteMain").innerHTML = Portal.SystemWebParts.Site.Site.GetHtml().value;
    document.getElementById("divProcessing").innerHTML = "";
}

function ShowDulicateSiteForm(SiteCode) {
    Url = Portal.SystemWebParts.Site.Site.GetDuplicateFormUrl(SiteCode).value;
    if (Url.indexOf("ERROR") != -1) {
        alert(Url);
        return;
    }
    window.open(Url, '_blank');
}

function ClientDuplicateSite(SiteCode) {
    NewSiteCode = document.getElementById("txtNewSiteCode").value;
    NewSiteTitle = document.getElementById("txtNewSiteTitle").value;
    IndexOrder = document.getElementById("txtIndexOrder").value;

    RetValue = Portal.SystemWebParts.Site.DuplicateSite.ServerSideDuplicateSite(SiteCode, NewSiteCode, NewSiteTitle, IndexOrder).value;
    if (RetValue.indexOf("ERROR") != -1) {
        alert(RetValue);
        return;
    }
    alert(RetValue);
    window.close();
}


function ClientSyncSite(SiteCode) {
    cMessage = Portal.SystemWebParts.Site.SyncSite.GetConfirmMsg().value;
    if (confirm(cMessage) == false) return;
    document.getElementById("divProcessing").innerHTML = "Đang đồng bộ dữ liệu...";
    setTimeout("RealClientSyncSite('" + SiteCode + "')", 10);
}

function RealClientSyncSite(SiteCode) {
    retValue = Portal.SystemWebParts.Site.SyncSite.ServerSideSyncSite(SiteCode).value;
    if (retValue.indexOf("ERROR") != -1) {
        document.getElementById("divProcessing").innerHTML = "";
        alert(retValue);
        return;
    }
    document.getElementById("divProcessing").innerHTML = "";
    alert(retValue);
}
